#!/usr/bin/perl

$WORKDIR= $ARGV[0];
$LEGODIR= $ARGV[1];

print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo "#! /bin/sh" > "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Voulez-vous savoir quels fichiers Uninstall_LEGO_NXT.sh va supprimer? (O/N)\" ; read ans' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'case \"\$ans\" in' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   o*|O*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"	Pour dsinstaller LEGO MINDSTORMS NXT, vous pouvez excuter ce fichier de script shell (\\\"Uninstall_LEGO_NXT.sh\\\")"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \" partir d'un shell Terminal.  Le script shell supprime les fichiers des rpertoires de niveau suprieur et des sous-rpertoires.  \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Tout fichier important dfini par l'utilisateur doit tre sauvegard ou dplac.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Vous pouvez supprimer manuellement les fichiers et les dossiers indiqus.  Les rpertoires \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"installs sont indiqus ci-dessous:\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Fichiers  supprimer pour LEGO MINDSTORMS NXT: \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"----------------------------------- \"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"$LEGODIR/LEGO MINDSTORMS NXT/...\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/Mindstorms*Ret.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/Mindstorms.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsDut.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsEng.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsFra.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsGer.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"/Library/Receipts/MindstormsJpn.pkg\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'esac' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Voulez-vous poursuivre la dsinstallation de LEGO MINDSTORMS NXT? (O/N)\" ; read ans' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'case "\$ans" in' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   n*|N*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   echo \"Dsinstallation annule.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   exit 0 ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   o*|O*)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Dsinstallation en cours.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Dsinstallation de LEGO MINDSTORMS NXT...\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -rf \"$LEGODIR/LEGO MINDSTORMS NXT\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/Mindstorms*Ret.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/Mindstorms.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsDut.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsEng.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsFra.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsGer.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsJpn.pkg' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'sudo rm -Rf /Library/Receipts/MindstormsDynamicBlockUpdate.pkg' >> "$LEGODIR/LEGO MINDSTORMS Edu NXT/Uninstall_LEGO_Edu_NXT.sh"`;
print `echo >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'echo \"Dsinstallation termine.\";;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   *)' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   echo \"Dsinstallation annule.\"' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo '   exit 0 ;;' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;
print `echo 'esac' >> "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;

print `sudo chmod 755 "$LEGODIR/LEGO MINDSTORMS NXT/Uninstall_LEGO_NXT.sh"`;

my	$results= `uname -p`;

chomp($results);

if ($results eq "powerpc") {
	print `sudo installer -pkg "$WORKDIR/../MindstormsPPCRet.pkg" -target /`;
	print `sudo installer -pkg "$WORKDIR/../MindstormsFraPPCRet.pkg" -target /`; 

	}
else {
	print `sudo installer -pkg "$WORKDIR/../Mindstormsi386Ret.pkg" -target /`; 
	print `sudo installer -pkg "$WORKDIR/../MindstormsFrai386Ret.pkg" -target /`; 
	}

	print `sudo cp -R -f -p "/private/tmp/LEGO MINDSTORMS NXT" "$LEGODIR"`;
	print `sudo rm -R -f "/private/tmp/LEGO MINDSTORMS NXT"`;
	print `sudo rm -f "/$LEGODIR/LEGO MINDSTORMS NXT/engine/BogusSizeFile"`;

